Fix HVM save/restore after upgrade to 0.90.
authorSteven Hand <steven@xensource.com>
Mon, 14 May 2007 14:19:46 +0000 (15:19 +0100)
committerSteven Hand <steven@xensource.com>
Mon, 14 May 2007 14:19:46 +0000 (15:19 +0100)
Signed-off-by: Steven Hand <steven@xensource.com>
tools/ioemu/vl.c

index 75d49f5c00c2cc76d22e234498c2ab3800719efb..32d5163b4e4f791b38b200ad09770ff62e9c58f1 100644 (file)
@@ -4891,6 +4891,77 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
     return ret;
 }
 
+#ifdef CONFIG_DM
+/* We use simpler state save/load functions for Xen */
+void do_savevm(const char *name)
+{
+    QEMUFile *f;
+    int saved_vm_running, ret;
+
+    f = qemu_fopen(name, "wb");
+    
+    /* ??? Should this occur after vm_stop?  */
+    qemu_aio_flush();
+
+    saved_vm_running = vm_running;
+    vm_stop(0);
+
+    if (!f) {
+        fprintf(logfile, "Failed to open savevm file '%s'\n", name);
+        goto the_end;
+    }
+    
+    ret = qemu_savevm_state(f);
+    qemu_fclose(f);
+
+    if (ret < 0)
+        fprintf(logfile, "Error %d while writing VM to savevm file '%s'\n",
+                ret, name);
+
+ the_end:
+    if (saved_vm_running)
+        vm_start();
+
+    return;
+}
+void do_loadvm(const char *name)
+{
+    QEMUFile *f;
+    int saved_vm_running, ret;
+
+    /* Flush all IO requests so they don't interfere with the new state.  */
+    qemu_aio_flush();
+
+    saved_vm_running = vm_running;
+    vm_stop(0);
+
+    /* restore the VM state */
+    f = qemu_fopen(name, "rb");
+    if (!f) {
+        fprintf(logfile, "Could not open VM state file\n");
+        goto the_end;
+    }
+
+    ret = qemu_loadvm_state(f);
+    qemu_fclose(f);
+    if (ret < 0) {
+        fprintf(logfile, "Error %d while loading savevm file '%s'\n",
+                ret, name);
+        goto the_end; 
+    }
+
+#if 0 
+    /* del tmp file */
+    if (unlink(name) == -1)
+        fprintf(stderr, "delete tmp qemu state file failed.\n");
+#endif
+
+
+ the_end:
+    if (saved_vm_running)
+        vm_start();
+}
+#else 
 void do_savevm(const char *name)
 {
     BlockDriverState *bs, *bs1;
@@ -5064,6 +5135,7 @@ void do_loadvm(const char *name)
     if (saved_vm_running)
         vm_start();
 }
+#endif
 
 void do_delvm(const char *name)
 {